testStage = JSGF.inherit(JSGF.Stage);

testStage.prototype.onLoad = function() {

	this.num = 100;
	this.slist = new Array();

	for (var i = 0; i < this.num; i++) {
		var imageFile = ["image/blue1.png", "image/blue2.png", "image/blue3.png", "image/blue4.png", ]
		//var sprite = JSGF.factory(JSGF.Sprite, imageFile, 50, 50);
		var sprite = JSGF.factory(JSGF.Sprite, imageFile);
		sprite.onImageLoad = function(s) {
			s.setWidth(50);
			s.setHeight(50);
		}
		//var sprite = JSGF.factory(JSGF.Sprite, "image/blue.png");
		sprite.move(Math.floor(Math.random() * 600) - 100, Math.floor(Math.random() * 600) - 100);
		sprite.setZIndex(i);
		sprite.startAnimation(100);
		sprite.setAlpha(0.8);
		this.appendSprite(sprite);
		this.slist.push(sprite);
	}

	this.testtext1 = JSGF.factory(JSGF.SpriteText, "イベント");
	this.testtext1.setZIndex(10000);
	this.testtext1.setColor("white");
	this.testtext1.setHeight(32);
	this.testtext1.move(100, 50);
	this.testtext1.setAlpha(0.5);
	this.appendSprite(this.testtext1);

	this.testtext2 = JSGF.factory(JSGF.SpriteText);
	this.testtext2.setZIndex(10000);
	this.testtext2.setColor("silver");
	this.testtext2.setHeight(32);
	this.testtext2.move(100, 100);
	this.appendSprite(this.testtext2);

	this.testrect1 = JSGF.factory(JSGF.SpriteRect, 100, 50);
	this.testrect1.setZIndex(10000);
	this.testrect1.setColor("blue");
	this.testrect1.setFill(false);
	this.testrect1.move(50, 150);
	this.appendSprite(this.testrect1);

	this.testrect2 = JSGF.factory(JSGF.SpriteRect, 100, 50);
	this.testrect2.setZIndex(10000);
	this.testrect2.setColor("blue");
	this.testrect2.setFill(true);
	this.testrect2.move(200, 150);
	this.testrect2.setAlpha(0.5);
	this.appendSprite(this.testrect2);

	this.testarc1 = JSGF.factory(JSGF.SpriteArc, 100, 50);
	this.testarc1.setZIndex(10000);
	this.testarc1.setColor("green");
	this.testarc1.setFill(false);
	this.testarc1.move(50, 250);
	this.appendSprite(this.testarc1);

	this.testarc2 = JSGF.factory(JSGF.SpriteArc, 100, 50);
	this.testarc2.setZIndex(10000);
	this.testarc2.setColor("green");
	this.testarc2.setFill(true);
	this.testarc2.move(200, 250);
	this.testarc2.setAlpha(0.5);
	this.appendSprite(this.testarc2);

	this.testarc3 = JSGF.factory(JSGF.SpriteArc, 50, 50);
	this.testarc3.setZIndex(10000);
	this.testarc3.setColor("green");
	this.testarc3.setFill(true);
	this.testarc3.move(350, 250);
	this.appendSprite(this.testarc3);

	this.testline = JSGF.factory(JSGF.SpriteLine, 100, 50);
	this.testline.setZIndex(10000);
	this.testline.setColor("yellow");
	this.testline.move(50, 350);
	this.appendSprite(this.testline);

	this.bg = JSGF.factory(JSGF.BackgroundImage, "image/b1.jpeg");
	//this.bg.setWidth(this.getWidth());
	//this.bg.setHeight(this.getHeight());
	this.appendBackgroundImage(this.bg);

	this.audio = JSGF.factory(JSGF.AudioSE, "sound/sound1");

	this.getController().useLocalStrage("test");
	var a = new Object();
	a["test1"] = 333;
	a["val"] = 888;
	var aa = new Object();
	aa["test1"] = 333;
	aa["val"] = 888;
	a["aa"] = aa;
	this.getController().setLocalStrage("testkey", a);
	var d = this.getController().getLocalStrage("testkey");
	this.testtext1.setText(d["aa"]["val"]);

	var self = this;
	setTimeout(function(){
		for (var i = 0; i < self.slist.length; i++) {
			self.slist[i].stopAnimation();
		}
	},5000);

	this.drawUpdate();

	this.startAnimation(16);

	var self = this;
	setTimeout(function() {
		self.stopAnimation();
		setTimeout(function() {
			self.getController().loadStage("testStage");
		}, 3000);
	}, 10000);
}

testStage.prototype.onUnload = function() {
	//alert("stage unload");
}

testStage.prototype.onDraw = function(dt) {
	this.testtext2.setText(dt + "ms " + this.getFps() + "fps");
	for (var i = 0; i < this.slist.length; i++) {
		var x = this.slist[i].getX();
		var y = this.slist[i].getY() + 4;
		if (y > this.getHeight()) {
			y = -(this.slist[i].getHeight());
		}
		this.slist[i].move(x, y);
	}
	this.bg.scroll(-2, -2);
}

testStage.prototype.onKeyDown = function(e) {
	this.testtext1.setText("keydown:"+e.keyCode);
}

testStage.prototype.onKeyUp = function(e) {
	this.testtext1.setText("keyup:"+e.keyCode);
}

JSGF.Stage.prototype.onClick = function(x, y) {
	this.testtext1.setText("onclick:"+x+","+y);
}

JSGF.Stage.prototype.onDblClick = function(x, y) {
	this.testtext1.setText("ondblclick:"+x+","+y);
}

JSGF.Stage.prototype.onMouseMove = function(x, y) {
	this.testtext1.setText("onmousemove:"+x+","+y);
}

JSGF.Stage.prototype.onMouseDown = function(x, y) {
	this.testtext1.setText("onmousedown:"+x+","+y);
	this.audio.play();
}

JSGF.Stage.prototype.onMouseUp = function(x, y) {
	this.testtext1.setText("onmouseup:"+x+","+y);
	this.audio.play();
}

